<template>
  <div>
    <el-table-form ref="form" :model="query">
      <el-form-item class="merge-item">
        <el-select v-model="query.type" style="width: 170px; margin-right: 2px;">
          <el-option label="电话" value="csmPhone" />
          <el-option label="客户编号" value="csmCode" />
          <el-option label="客户名称" value="csmName" />
          <el-option label="地址" value="csmAddress" />
        </el-select>
        <el-input v-model.trim="query.csmText" placeholder="请输入" clearable />
      </el-form-item>
      <template v-slot:btns>
        <el-button v-permission="8" type="primary" icon="el-icon-search" @click="search">查询</el-button>
      </template>
    </el-table-form>
    <el-button v-permission="9" style="margin-bottom: 5px;" type="primary" @click="move">移动</el-button>
    <lb-table
      ref="lbTable"
      v-el-height-adaptive-table="{bottomOffset:10}"
      v-loading="$loadingPlugin.fetchData"
      border
      highlight-current-row
      element-loading-text="加载中"
      :column="tableData.column"
      :data="tableData.data"
      pagination
      :total="tableData.total"
      custom-column
      @selection-change="handleSelectionChange"
      @fetch="fetchData"
    />
    <move ref="move" @refresh="refresh" />
  </div>
</template>

<script>
  import { orderSendPlan2CustomerList } from '@/api'
  export default {
    name: 'userSearch',
    components: {
      move: require('./move.vue').default
    },
    data() {
      return {
        query: {
          csmText: null,
          type: 'csmPhone'
        },
        submitAuditList: [],
        tableData: {
          total: 0,
          column: [
            { type: 'selection', align: 'center' },
            { type: 'index', align: 'center' },
            { label: '客户编号', prop: 'csmCode' },
            { label: '客户名称', prop: 'csmName' },
            { label: '客户电话', prop: 'csmPhone' },
            { label: '地址', prop: 'csmAddress', showOverflowTooltip: true },
            { label: '配送机构', prop: 'orgName' },
            { label: '所属配送计划', prop: 'planName' }
          ],
          data: []
        }
      }
    },
    methods: {
      modeChange() {

      },
      async fetchData({ currentPage = 1, pageSize = 20 }) {
        const params = {
          status: 2,
          planCode: this.planCode,
          currentPage,
          pageSize
        }
        params[this.query.type] = this.query.csmText
        const res = await orderSendPlan2CustomerList(params)
        this.tableData.data = res.data.rows
        if (currentPage === 1) this.tableData.total = res.data.total
      },
      search() {
        this.fetchData({})
      },
      handleSelectionChange(val) {
        this.submitAuditList = [...val]
      },
      refresh() {
        this.fetchData({})
      },
      async move() {
        if (!this.submitAuditList.length) {
          this.$message.error('请先选择客户')
          return ''
        }
        this.$refs.move.open(this.submitAuditList)
      }
    }
  }
</script>
